<?php

/**
 * Description of FaqManager_PDO
 *
 * @author FFOZEU
 */
namespace Applications\Modules\Faq\Models;

if( !defined('IN') ) die('Hacking Attempt');

class FaqManager_PDO extends FaqManager{
    //put your code here
    
    public function getFaqListe(){
        $sql = 'SELECT f.*
                FROM '.$this->nameTable.' as f
                ORDER BY f.position';
        $faq=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($faq, $this->name);
                
    }
    
    public function getActiveFaq(){
        $sql = 'SELECT f.*
                FROM '.$this->nameTable.' as f 
                WHERE f.isactive="1"
                ORDER BY f.position';
        $faq=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($faq, $this->name);
    }
    public function addFaq(array $faq){
        $afaq = new Faq($faq);
        $sql='INSERT INTO '.$this->nameTable.'
              SET position = :position, isactive = :isactive, question = :question, answer = :answer';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':position',$afaq->getPosition());
        $req->bindParam(':isactive',$afaq->getIsactive());
        $req->bindParam(':question',$afaq->getQuestion());
        $req->bindParam(':answer',$afaq->getAnswer());
        
        return $req->execute();
    }
    
    public function updateFaq(array $faq){
        $afaq = new Faq($faq);
        $sql='UPDATE '.$this->nameTable.'
              SET position = :position, isactive = :isactive, question = :question, answer = :answer
              WHERE id = :id';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':position',$afaq->getPosition());
        $req->bindParam(':isactive',$afaq->getIsactive());
        $req->bindParam(':question',$afaq->getQuestion());
        $req->bindParam(':answer',$afaq->getAnswer());
        $req->bindParam(':id',intval($afaq->getId()));
        
        return $req->execute();
    }
    
    public function getFaqById($id){
        
        return $this->fecthRow_data($this->findById($this->nameTable, $id), $this->name);
    }
    
    public function deleteFaq(array $id){
        
        return $this->delete($this->nameTable, $id);
    }
}

?>
